/**
 * LoadingDialog.java
 * classes : com.dld.view.LoadingDialog
 *
 * @author cdj
 * V 1.0.0 * Create at 2014-8-14 下午4:10:48
 */
package com.smartdot.bluetoothidcarddemo.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartdot.bluetoothidcarddemo.R;
import com.smartdot.bluetoothidcarddemo.http.ProgressCancelListener;

/**
 * Created by LUOLI on 16/3/10.
 */

public class LoadingDialog extends Dialog {
    private TextView tip_Tv;
    private ImageView loding_Iv;

    public LoadingDialog(Context context) {
        this(context, R.style.dialog);
    }

    public LoadingDialog(Context context, int style) {
        super(context, style);
        setContentView(R.layout.dialog_loading);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
        loding_Iv = (ImageView) findViewById(R.id.loding_Iv);
        tip_Tv = (TextView) findViewById(R.id.tip_Tv);
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                context, R.anim.loading_animation);
        hyperspaceJumpAnimation.setInterpolator(new LinearInterpolator());
        loding_Iv.startAnimation(hyperspaceJumpAnimation);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    /**
     * @param content
     * @Description:[设置加载信息]
     */
    public void setText(String content) {
        if (!TextUtils.isEmpty(content)) {
            tip_Tv.setText(content);
            tip_Tv.setVisibility(View.VISIBLE);
        } else {
            tip_Tv.setVisibility(View.GONE);

        }
    }

    public void setImg(int imgId) {
        loding_Iv.setImageResource(imgId);
    }

    /**
     * 设置图片是否隐藏   true 隐藏    false  显示
     *
     * @param b
     */
    public void setHintImg(boolean b) {
        if (b)
            loding_Iv.setVisibility(View.GONE);
        else
            loding_Iv.setVisibility(View.VISIBLE);
    }

    private ProgressCancelListener mProgressCancelListener;

    public void setProgressCancelListener(ProgressCancelListener progressCancelListener) {
        mProgressCancelListener = progressCancelListener;
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mProgressCancelListener != null) {
            mProgressCancelListener.onCancelProgress();
        }
    }
}
